/**
 * a class represents the coverage matrix
 */
public class CoverageMatrix 
{
	int[][] arr;
	
	public CoverageMatrix(int[][] matrix, int N, int M) //N = num of tests, M = num of components
	{
		//deep copy arr
		arr = new int[N][];
		for(int i = 0; i < N; i++) arr[i] = new int[M];
		for(int i = 0; i < N; i++)
			for(int j = 0; j < M; j++) arr[i][j] = matrix[i][j];
	}
	/**
	 * checks if c covered by t
	 * @param c - component 
	 * @param t - test
	 * @return
	 */
	public boolean isComponentCoveredByTest(Component c, Test t)
	{
		return arr[t.getId()][c.getId()] > 0;
	}
	
	/**
	 * sets c is covered by t to be flag  
	 * @param c - component
	 * @param t - test
	 * @param flag - boolean - is c covered by t?
	 */
	public void setIsComponentCoveredByTest(Component c, Test t, boolean flag)
	{
		arr[t.getId()][c.getId()] = flag == true ? 1 : 0;
	}
	
	/**
	 * adding a row to arr
	 */
	public void addRow(int[] row)
	{
		int[][] arr2 = new int[arr.length+1][];
		for(int i = 0; i < arr2.length-1; i++)
			arr2[i] = arr[i];
		arr2[arr.length] = row;
		arr = arr2;
	}
	
	/**
	 * getter for arr
	 * @return
	 */
	public int[][] getArray()
	{
		return arr;
	}
	
	public String toString()
	{
		String ans = "";
		for(int i = 0; i < arr.length; i++)
		{
			for(int j = 0; j < arr[i].length; j++)
				ans += (arr[i][j] + " ");
			ans += "\n";
		}
		return ans;
	}
}
